package hbase;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;

public class GetTest {

	public static void main(String[] args) throws MasterNotRunningException, ZooKeeperConnectionException, IOException {
		
		Configuration conf = HBaseConfiguration.create();
		conf.set("hbase.zookeeper.quorum", "master");
		
		HBaseAdmin admin = new HBaseAdmin(conf);
		HTable table = new HTable(conf, "user");
		try {
			
			Get get = new Get(Bytes.toBytes("yangrui"));
			Result result = table.get(get);
			System.out.println("get result:" + Bytes.toString(result.getValue(Bytes.toBytes("teacher"), Bytes.toBytes("math"))));
			System.out.println("get result:" + Bytes.toString(result.getValue(Bytes.toBytes("teacher"), Bytes.toBytes("chinese"))));
			System.out.println("get result:" + Bytes.toString(result.getValue(Bytes.toBytes("teacher"), Bytes.toBytes("english"))));
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			table.close();
			admin.close();
		}
	}
}
